2015-10-03(腾工).txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. if not exists
  2. (select * from syscolumns where id=object_id('tb_ErpOrdersPhotography') and name='Ordpg_SightsRemark')
  3. begin
  4. alter table tb_ErpOrdersPhotography add Ordpg_SightsRemark nvarchar(800) NULL
  5. end
  6. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpOrdersPhotography', N'COLUMN',N'Ordpg_SightsRemark'))
  7. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'景点备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpOrdersPhotography', @level2type=N'COLUMN',@level2name=N'Ordpg_SightsRemark'
  8. GO
  9. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityOpenOrderFriendSelect')
  10. BEGIN
  11. DROP VIEW [dbo].BView_DoorCityOpenOrderFriendSelect
  12. END
  13. GO
  14. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityOpenOrderFriendSelect]'))
  15. EXEC dbo.sp_executesql @statement = N'
  16. CREATE VIEW [dbo].[BView_DoorCityOpenOrderFriendSelect]
  17. AS
  18. SELECT
  19. dbo.tb_ErpCustomer.ID,
  20. Cus_CustomerNumber,
  21. Cus_Type,
  22. Cus_Name,
  23. Cus_NamePinyin,
  24. Cus_Telephone,
  25. Cus_Sex,
  26. Mc_CradNumber
  27. FROM dbo.tb_ErpCustomer LEFT OUTER JOIN
  28. dbo.tb_ErpMemberCard ON
  29. Cus_CustomerNumber = Mc_CustomerNumber AND
  30. Mc_CradNumber <> ''''
  31. '
  32. GO
  33. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberMain_GoldMember')
  34. BEGIN
  35. DROP VIEW [dbo].BView_MemberMain_GoldMember
  36. END
  37. GO
  38. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberMain_GoldMember]'))
  39. EXEC dbo.sp_executesql @statement = N'
  40. CREATE VIEW [dbo].[BView_MemberMain_GoldMember]
  41. AS
  42. SELECT Cus_ID, ID AS Mc_ID,
  43. Mc_Status,
  44. Mc_Number,
  45. Mc_CradNumber AS 会员卡号,
  46. Cus_Name AS 姓名,
  47. Cus_CustomerNumber AS 姓名编号,
  48. dbo.fn_CheckSex(Cus_Sex) AS 性别,
  49. Cus_Telephone AS 电话,
  50. Mc_CardType AS 类型,
  51. dbo.fn_GetMember(Mc_Number, 1) AS 积分,
  52. Mc_Money AS 金额,
  53. dbo.fn_GetMember(Mc_Number, 2) AS 折扣,
  54. dbo.fn_GetMember(Mc_Number, 3) AS 套系金额,
  55. dbo.fn_GetMember(Mc_Number, 4) AS 已返金额,
  56. dbo.fn_GetMember(Mc_Number, 5) AS 已取出金额,
  57. (SELECT COUNT(Mcse_ServiceCount) AS Expr1 FROM dbo.tb_ErpMemberCardServiceContent WHERE (Mcse_Number = dbo.BView_MemberCard.Mc_Number)) AS 服务次数,
  58. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''积分副卡'')) AS 积分副卡,
  59. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_2 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''现金副卡'')) AS 现金副卡,
  60. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_1 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''返现副卡'')) AS 返现副卡,
  61. Mc_Remark AS 备注,
  62. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Mc_CreateDatetime)) AS 办卡日期
  63. FROM dbo.BView_MemberCard
  64. WHERE (Mc_Status = ''1'')
  65. '
  66. GO
  67. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthReworkStatistic')
  68. BEGIN
  69. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthReworkStatistic
  70. END
  71. GO
  72. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]'))
  73. EXEC dbo.sp_executesql @statement = N'
  74. CREATE VIEW [dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]
  75. AS
  76. SELECT
  77. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, tb_ErpOrderProductList_1.ID AS PPID,
  78. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  79. Ordv_DigitalNumber,
  80. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  81. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  82. Cus_Name AS 客户姓名,
  83. Cus_Name_py AS 客户拼音,
  84. Cus_Sex_cs AS 客户性别,
  85. Cus_Telephone AS 客户电话,
  86. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  87. tb_ErpOrderProductList_1.OPlist_Class,
  88. (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  89. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  90. dbo.fn_CheckProductReworkStatus(tb_ErpOrderProductList_1.OPlist_ReworkStatus)
  91. + CASE OPlist_ReworkRemark WHEN '''' THEN '''' ELSE ''/['' + OPlist_ReworkRemark + '']'' END AS 是否返工,
  92. OPlist_ReworkRemark2 AS 返工原因,
  93. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_ReworkTime)) AS 返工日期,
  94. tb_ErpOrderProductList_1.OPlist_ReworkTime AS 返工日期查询,
  95. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  96. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  97. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  98. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  99. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  100. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  101. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  102. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  103. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  104. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  105. '
  106. GO